package com.eco.fanliapp.admin.controller.web;

import com.eco.fanliapp.admin.common.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.SyAdminLoginIp;
import com.eco.fanliapp.service.ISyAdminLoginIpService;
import com.eco.fanliapp.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/web/loginIp")
public class SyAdminLoginIpController extends BaseController {
    @Autowired
    private ISyAdminLoginIpService syAdminLoginIpService;



    @GetMapping("/loginIpList")
    @ResponseBody
    public ServerResponse loginIpList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20")Integer pageSize,String keyWord){
        Integer companyId = getAuthentication().getCompanyId();
        return syAdminLoginIpService.loginIpList(pageNum,pageSize,companyId,keyWord);
    }

    @PostMapping("/saveAndUpdate")
    @ResponseBody
    public  ServerResponse saveAndUpdate(@RequestBody SyAdminLoginIp syAdminLoginIp){
        UserVO authentication = getAuthentication();
        if(syAdminLoginIp.getInCompanyId() == null || syAdminLoginIp.getInCompanyId() == 0){
            syAdminLoginIp.setCompanyId(authentication.getCompanyId());
        }else{
            syAdminLoginIp.setCompanyId(syAdminLoginIp.getInCompanyId());
        }
        return syAdminLoginIpService.saveAndUpdate(syAdminLoginIp);
    }

    @GetMapping("/delete")
    @ResponseBody
    public  ServerResponse delete(Integer tableId){
        return syAdminLoginIpService.delete(tableId);
    }
}
